<?php

class FileHelper
{

    protected static $baseDir;

    /**
     * Deletes a file.
     *
     * @param string $filename
     * @return <type>
     */
    public static function deleteFile($filename)
    {
        if (!is_writable($filename)) {
            throw new Exception($filename . ' is not writable.');
        }
        return unlink(self::$baseDir . $filename);
    }

    /**
     * Reads a file.
     *
     * @param string $filename
     * @return string
     */
    public static function readFile($filename)
    {
        if (!is_readable($filename)) {
            throw new Exception($filename . ' is not readable.');
        }
        return file_get_contents(self::$baseDir . $filename);
    }

    /**
     *
     * @param string $baseDir
     * @return void;
     */
    public static function setBaseDir($baseDir)
    {
        self::$baseDir = $baseDir;
    }

    /**
     * Writes a file.
     *
     * @param string $filename
     * @param string $data
     * @return <type>
     */
    public static function writeFile($filename, $data)
    {
        if (!is_writable($filename)) {
            throw new Exception($filename . ' is not writable.');
        }
        return file_put_contents(self::$baseDir . $filename, $data);
    }
}